package com.bovink.customalbum;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.bovink.customalbum.album.AlbumActivity;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button openCustomBtn = (Button) findViewById(R.id.btn_album);

        openCustomBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, AlbumActivity.class);
                startActivityForResult(intent, AlbumActivity.SELECT_ALBUM_IMAGE);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == AlbumActivity.SELECT_ALBUM_IMAGE) {

            if (resultCode == RESULT_OK) {

                List<String> imgList = (List<String>) data.getSerializableExtra("data");
                for (int i = 0; i < imgList.size(); i++) {
                    System.out.println("imgList.get(i) = " + imgList.get(i));
                }
            } else if (resultCode == RESULT_CANCELED) {

                System.out.println("MainActivity.onActivityResult");
            }
        }
    }
}
